<?php

namespace addons\oil\library\traits\model\order;

use addons\oil\model\Order;
use think\Cache;

trait OrderStatus
{

    public function getStatusNameAttr($value, $data)
    {
        return $this->getStatus($data, 'status_name');
    }

    public function getStatusDescAttr($value, $data)
    {
        return $this->getStatus($data, 'status_desc');
    }


    public function getBtnsAttr($value, $data)
    {
        return $this->getStatus($data, 'btns');
    }


    // 获取订单状态
    public function getStatusCodeAttr($value, $data)
    {
        $status_code = '';

        switch ($data['status']) {
            case Order::STATUS_CANCEL:
                $status_code = 'cancel';        // 订单已取消
                break;
            case Order::STATUS_INVALID:
                $status_code = 'invalid';        // 订单交易关闭
                break;
            case Order::STATUS_NOPAY:
                $status_code = 'nopay';        // 订单等待支付
                break;
            case Order::STATUS_PAYED:
                // 根据 获取支付后的状态信息
                $status_code = $this->getPayedStatusCode($data);
                break;
            case Order::STATUS_FINISH:
                $status_code = 'finish';
                break;
            case Order::STATUS_SHARE:
                $status_code = 'share';
                break;
        }

        return $status_code;
    }
    /**
     * 获取支付成功之后的子状态
     */
    public function getPayedStatusCode($data)
    {
        $status_code = '';
        //没申请退款，显示为已支付
        if($data['refund_status']==Order::REFUND_STATUS_NOREFUND){
            $status_code= 'payed';
        }
        // 退款完成
        if (in_array($data['refund_status'], [Order::REFUND_STATUS_OK, Order::REFUND_STATUS_FINISH])) {
            $status_code= 'refund_finish';
        }
        if($data['refund_status']==Order::REFUND_STATUS_ING){
            $status_code= 'refund_ing';
        }
        if($data['refund_status']==Order::REFUND_STATUS_REFUSE){
            $status_code= 'refund_refuse';
        }
        return $status_code;
    }

}
